package util;

import java.util.ArrayList;

/**
 * Created by Tecnocom on 1/26/2015.
 */
public class MyParameters {
    ArrayList<MyFieldObject> data;
    public MyParameters(){
        data = new ArrayList<MyFieldObject>();
    }

    public void add(String value, String key){
        MyFieldObject d = new MyFieldObject(key,value);
        data.add(d);
    }

    public void add(int value, String key){
        String valueStr;
        if(value == -999)
            valueStr = "";
        else
            valueStr = ""+value;
        MyFieldObject d = new MyFieldObject(key,valueStr);
        data.add(d);
    }

    public ArrayList<MyFieldObject> getParameters(){
        return data;
    }

    public String validateMandatoryData(){
        MyParameters p = this;
        ArrayList<MyFieldObject> data = p.getParameters();
        String res = "";
        int j=0;
        for(int i=0;i<data.size();++i){
            if(data.get(i).value.compareTo("")==0){
                j++;
                if(j == 1)
                    res = data.get(i).key;
                else
                    res = res + ", " + data.get(i).key;
            }
        }
        if(j == 1)
            res = "El campo '"+res+"' es obligatorio. Verifique.";
        if(j > 1)
            res = "Los campos: '"+res+"' son obligatorios. Verifique.";

        return res;
    }
}
